﻿using Halcon二次开发.Controller.精准测量模块功能;
using Halcon二次开发.Model.自定义控件;
using Halcon二次开发.Tools;
using Halcon二次开发.View.中心距;
using Halcon二次开发.View.卡尺;
using Halcon二次开发.View.多文本显示工具;
using Halcon二次开发.View.应用_加载框;
using Halcon二次开发.View.结果分析工具;
using Halcon二次开发.View.角度界面;
using Halcon二次开发.View.缺陷检测;
using Halcon二次开发.View.距离转换工具;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Halcon二次开发.View.精准测量模块
{
    public partial class CaliperModuleForm : Form
    {
        #region 模块化窗体组成对象
        public PreciseCaliper caliperForm;
        public DistanceToolForm distanceForm;
        public AnalyseResultForms analyseForm;
        public MessageBoxStringsForms messageForm;
       
        public DistanceForm distansceForm;
        public AnagleForm anagleForm;
        public BoldForm boldForm;
        #endregion

        public CaliperModuleController controller;

        HwindowFlowNodeUrseControl hwindowFlowNode;
        public CaliperModuleForm(HwindowFlowNodeUrseControl hwindowFlowNode)
        {
            InitializeComponent();
            this.hwindowFlowNode = hwindowFlowNode; 
            controller = new CaliperModuleController(this,hwindowFlowNode);
            
        }
        /// <summary>
        /// 加载窗体对象
        /// </summary>
        public void LoadAntherForm()
        {
            caliperForm = new PreciseCaliper(this.Name, hwindowFlowNode);
            distanceForm = new DistanceToolForm(this.Name, hwindowFlowNode);
            analyseForm = new AnalyseResultForms(this.Name, hwindowFlowNode);
            messageForm = new MessageBoxStringsForms(this.Name, hwindowFlowNode);


            //角度界面
            anagleForm = new AnagleForm(this.Name,hwindowFlowNode);
            //中心距界面
            distansceForm = new DistanceForm(this.Name, hwindowFlowNode);
            boldForm = new BoldForm(this.Name, hwindowFlowNode);
            Utiy.AddPage(caliperForm, tabPage1);
            Utiy.AddPage(distanceForm, tabPage2);
            Utiy.AddPage(analyseForm, tabPage3);
            Utiy.AddPage(messageForm, tabPage4);
            Utiy.AddPage(distansceForm, tabPage5);
            Utiy.AddPage(anagleForm, tabPage7);
            Utiy.AddPage(boldForm, tabPage6);
        }
        private void CaliperModuleForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            //关闭是清除基准线对象与对位线对象
            try
            {
                if (anagleForm.controller.lineObjCounterpoint != null)
                {
                    anagleForm.controller.lineObjCounterpoint.Dispose();
                    anagleForm.controller.lineObjCounterpoint.ClearDrawingObject();
                }
                if (anagleForm.controller.lineObjStandard != null)
                {
                    anagleForm.controller.lineObjStandard.Dispose();
                    anagleForm.controller.lineObjStandard.ClearDrawingObject();
                }
                if (caliperForm != null)
                {
                    caliperForm.controller.ClearObject();
                }
                if (caliperForm.controller.line1Object != null)
                {
                    caliperForm.controller.line1Object.ClearDrawingObject();
                }
                if (caliperForm.controller.line2Object != null)
                {
                    caliperForm.controller.line2Object.ClearDrawingObject();
                }

                this.Hide();
                e.Cancel = true;
            }
            catch { }
        }

        /// <summary>
        /// 反射调用该方法更新窗体句柄
        /// </summary>
        /// <param name="hwindowFlowNode"></param>
        public void PushHWindon(HwindowFlowNodeUrseControl hwindowFlowNode)
        {
            this.hwindowFlowNode = hwindowFlowNode;
            controller.hwindowFlowNode = hwindowFlowNode;

            caliperForm.PushHWindon(hwindowFlowNode);
            messageForm.PushHWindon(hwindowFlowNode);
        }
    }
}
